// JavaScript Document
function add_friend(friend_id){
	$.ajax({
	  type: 'GET',
	  url: './module/user/function_friend.php',
	  data: {act:'addfriend', val: friend_id },
	  success: function(data) {
		  if(data==0){
			  alert ('Error transfer');
		  } else if(data==1) {
			  $('#bt_'+friend_id).html('<span class="note">Wait accept</span>');
		  } else if(data==2) {
			  alert ('ERROR cannot add friend');
		  } else if(data==3) {
			  $('#bt_'+friend_id).html('<span class="note">Duplicate!</span>');
		  } else if(data==4) {
			   alert ('ERROR database not ready');
		  } else {
			  alert ('Unknown Error \n'+ data );
		  }
	  },
	  error: function (){ alert ('Cannot get function file');}
  });
}

function load_myfriend(group, start_user){
	$.ajax({
	  type: 'GET',
	  url: './module/user/load_user_group.php',
	  data: {act:'myfriend', gru : group, val: start_user },
	  dataType: 'html',
	  success: function(data) {
		  if(data==0){
			  alert ('Error transfer');
		  } else {
			  $('#my_friend').html(data);
			  window.location.hash = start_user;
		  }
	  },
	  error: function (){ alert ('Cannot get function file');}
	});
}

function load_user(){
	$.ajax({
	  type: 'GET',
	  url: './module/user/load_user_group.php',
	  data: {act:'randomuser'},
	  dataType: 'html',
	  success: function(data) {
		  $('#user_random').html(data);
	  },
	  error: function (){ alert ('Cannot get function file');}
	});
}

function load_group(link_g,current){
	$.ajax({
	  type: 'GET',
	  url: './module/user/load_user_group.php',
	  data: {act:'grouplist', val: link_g, pos:current},
	  dataType: 'html',
	  success: function(data) {
		  $('#bt_new_group').before(data);
	  },
	  error: function (){ alert ('Cannot get function file');}
	});
}

function new_group(){
	$.ajax({
	  type: 'GET',
	  url: './module/user/load_user_group.php',
	  data: {act:'newgroup'},
	  dataType: 'html',
	  success: function(data) {
		  $('#new_group').html(data);
		  $('#content_newgroup').slideDown();
		  $("#groupname").focus();
	  },
	  error: function (){ alert ('Cannot get function file');}
	});
}

function add_member_list(fol){
	$.ajax({
	  type: 'GET',
	  url: './module/user/load_user_group.php',
	  data: {act:'friendlist', val: fol},
	  dataType: 'html',
	  success: function(data) {
		  $('#loadlistfriend').html(data).slideDown();
	  },
	  error: function (){ alert ('Cannot get function file');}
	});
}

function add_member(fol){
	var values = new Array();
	$.each($("#loadlistfriend").find("input[name='select_friend']:checkbox:checked"), function() {
 		 values.push($(this).val());
	});
	values = values.reverse()

	$.ajax({
	  type: 'GET',
	  url: './module/user/function_friend.php',
	  data: {act:'addmember', pos: fol, val: values},
	  dataType: 'html',
	  success: function(data) {
		  closethis();
		  window.document.location.reload();
	  },
	  error: function (){ alert ('Cannot get function file');}
	});
}

function edit_group(fol){
	$.ajax({
	  type: 'GET',
	  url: './module/user/load_user_group.php',
	  data: {act:'editgroup', val:fol},
	  dataType: 'html',
	  success: function(data) {
		  $('#edit_group').html(data).slideDown();
		  $("#group_editname").focus();
	  },
	  error: function (){ alert ('Cannot get function file');}
	});
}

function closethis(){
	$('.smak_onpage').slideUp('normal');
}


